#! /bin/sh
# Examples of segyread and segywrite
# Author: John Stockwell
set -x

##### Example 1 --- reading data from a tape to a file
##
## processing steps:
##	1) segyread  ---- read the data from tape
##	2) segyclean ---- zero optional fields in SEGY header
##	3) > outfile.su   ----  redirect stdout to file
##
## additional info: selfdocs of segyread, segyclean, and segywrite

### set parameters for segyread
trmin=first_tr	# trace number of first trace to be read (optional)
trmax=last_tr	# trace number of last trace to be read (optional)

tape="/dev/r*** "	# raw tape device being read from
outfile="outfile.su"	# output filename
bfile=binary		# BINARY header filename
hfile=header		# ASCII header filename
verbose=1		# =1 list more info ;  =0 (default) silent
buff=1			# =1 (default) for 9 trac tape;  =0 for EXABYTE

segyread	verbose=$verbose \
		buff=$buff \
		tape=$tape \
		trmin=$trmin \
		trmax=$trmax \
		bfile=$bfile \
		hfile=$hfile |
segyclean > $outfile

exit 0

##### Example 2 --- reading data from a file to a tape
##
## processing steps:
##	1) segyhdrs  ---- to make ASCII and BINARY header files
##	2) segywrite < infile ---- to write data in 'infile' to a tape
##
## additional info: selfdocs of segyread, segyhdrs, and segywrite

### set parameters for segywrite

tape="/dev/r*** "	# raw tape device being written to
infile="infile.su"	# input filename of SEGY data
bfile=binary		# binary header filename
hfile=header		# ascii header filename
verbose=1		# =1 list more info ;  =0 (default) silent
buff=1			# =1 (default) for 9 trac tape;  =0 for EXABYTE

### make ASCII and BINARY header files
segyhdrs < $infile hfile=$hfile bfile=$bfile

segywrite < $infile	verbose=$verbose \
			buff=$buff \
			tape=$tape \
			bfile=$bfile \
			hfile=$hfile 
exit 0

##### Example 3	---	reading data from a tape, processing it, writing to
#####			a tape on another tape drive as a continuous process
##
## processing steps:
##	1) segyread --- to get ASCII and BINARY tape header files: hfile1
##			bfile1 from beginning of tape
##	2) segyread --- again, now to get full data set from tape, but being 
##	   		careful to output ASCII and BINARY tape headers to
##			to hfile2 and bfile2
##	3) segyclean --	to zero optional segy header fields
##	4) ... desired processes for segydata ...
##	5) segywrite -- write to other tape drive, being careful to input
##			ASCII and BINARY tape header files hfile1 and bfile1
##
## additional info: selfdocs of segyread, segyclean, and segywrite

### set parameters for segyread
trmin=first_tr	# trace number of first trace to be read (optional)
trmax=last_tr	# trace number of last trace to be read (optional)

tape1="/dev/r*** "	# raw tape device being read from
tape2="/dev/r*** "	# raw tape device being written to (not tape1)
outfile="outfile.su"	# output filename
bfile1=binary1		# BINARY header filename 1
hfile1=header1		# ASCII header filename 1
bfile2=binary2		# BINARY header filename 2
hfile2=header2		# ASCII header filename 2
verbose=1		# =1 list more info ;  =0 (default) silent
buff=1			# =1 (default) for 9 trac tape;  =0 for EXABYTE

# first pass of segyread to get binary header
segyread	verbose=$verbose \
		buff=$buff \
		tape=$tape1 \
		trmin=first_trace \
		trmax=second_trace \
		bfile=$bfile1 \
		hfile=$hfile1  > /dev/null 

# second pass of segyread to get all desired traces
segyread	verbose=$verbose \
		buff=$buff \
		tape=$tape1 \
		trmin=$trmin \
		trmax=$trmax \
		bfile=$bfile2 \
		hfile=$hfile2 | 
segyclean |
... other process ... | ... | ... |
segywrite 	verbose=$verbose \
		buff=$buff \
		tape=$tape \
		bfile=$bfile1 \
		hfile=$hfile1 

exit 0



